# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Timo Teräs <timo.teras@iki.fi>
pkgname=unzip
pkgver=6.0
_pkgver=${pkgver//./}
pkgrel=9
pkgdesc="Extract PKZIP-compatible .zip files"
url="http://www.info-zip.org/UnZip.html"
arch="all"
license="custom"
subpackages="$pkgname-doc"
# normally 	ftp://ftp.info-zip.org/pub/infozip/src/$pkgname$_pkgver.zip
source="https://dev.alpinelinux.org/archive/unzip/unzip$_pkgver.tgz
	10-unzip-handle-pkware-verify.patch
	20-unzip-uidgid-fix.patch
	unzip-6.0-heap-overflow-infloop.patch
	CVE-2014-8140.patch
	CVE-2014-8141.patch
	CVE-2014-9636.patch
	CVE-2014-9913.patch
	CVE-2016-9844.patch
	CVE-2018-1000035.patch
	fix-CVE-2014-8139.patch
	CVE-2019-13232.patch
	CVE-2018-18384.patch
	"
builddir="$srcdir/$pkgname$_pkgver"

# secfixes:
#   6.0-r9:
#     - CVE-2018-18384
#   6.0-r7:
#     - CVE-2019-13232
#   6.0-r3:
#     - CVE-2014-8139
#     - CVE-2014-8140
#     - CVE-2014-8141
#     - CVE-2014-9636
#     - CVE-2014-9913
#     - CVE-2016-9844
#     - CVE-2018-1000035
#   6.0-r1:
#     - CVE-2015-7696
#     - CVE-2015-7697

# failing tests
case "$CARCH" in
	arm*) options="$options !check" ;;
esac

build() {
	make -f unix/Makefile \
		CC="$CHOST-gcc" \
		LOCAL_UNZIP="$CFLAGS $CPPFLAGS -DNO_LCHMOD" \
		prefix=/usr generic
}

check() {
	make -f unix/Makefile check
}

package() {
	make -f unix/Makefile \
		MANDIR=$pkgdir/usr/share/man/man1/ \
		prefix=$pkgdir/usr install
	install -Dm644 LICENSE \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

sha512sums="
0694e403ebc57b37218e00ec1a406cae5cc9c5b52b6798e0d4590840b6cdbf9ddc0d9471f67af783e960f8fa2e620394d51384257dca23d06bcd90224a80ce5d  unzip60.tgz
9d2914f22fb0075a2b6f72825c235f46eafd8d47b6fb6fcc8303fc69336e256b15923c002d2615bb6af733344c2315e4a8504d77bae301e10c11d4736faa2c81  10-unzip-handle-pkware-verify.patch
57699582e9056af0817dcb67f8db67e6a1ff8208c137fbebcf559429e5f12b471b75d7e1ef938e5bbb5416074a51ac7342e4ce8057f4bbdcb0bf079b8d7832af  20-unzip-uidgid-fix.patch
b0b745cff474756447e699a13ff003871b33a4f7a24a91150e5a947eba5132fd90fbacf7580379fc13c5f638483b25cbc226f85b9cac9c7662b2f91927eb2bb3  unzip-6.0-heap-overflow-infloop.patch
028a97e781fb4e277df331fd40b848bbc002f1a5ceeb40e74477cf68d2f063ac2623e24afbeddfa0456940ecc7694fdb66ecd031cbcecad63079e8427fb731c9  CVE-2014-8140.patch
3dd21343d6e5ae7d19f2b2f9cf7310eac38dd7f598e1265e247559a48143c9dbffabd9fc0d7aff6d859ec9e646e85c2b7ee00a1b1a2e23bdf96192c22c58b058  CVE-2014-8141.patch
281c524a9adb1c0f1cb861548d96115f55152c1d76adca34bbaabcca410c5aaf5dd53d99360d7ea8ee9d0ab9eb62031cb40c5de4b5ecfd91535ac178cd3e7098  CVE-2014-9636.patch
9a62286acdbd5bf5f679d813017b93c25bdb06edaf48b2b53d3281ce3c30587158a777b07457c574d72350499f786dac6b4493092d7e08c17c07cb65ecc513b6  CVE-2014-9913.patch
8c4a4313072ff0d87eadb0f5472eb48f2802b835dd282305811a96de87a41fed48be60fbdd434e6b6359418f0559f7793deaa1d68161a0c0ead9f8574bb9f14c  CVE-2016-9844.patch
6f757385a23fe6a034f676df6bf233243afa8743761e3d715e532d066fcd7dc8f8dcd6192be693258f3855837e5534490784378768abe7ce710fb869258d49b7  CVE-2018-1000035.patch
13f9c54fcdde478c4afe391c8e7ef9c31b03228aaace5da38382612951cbfd60710fd3d931569297953be32b2c5906715aed4b1c05e28cc8fccbb27f38b57550  fix-CVE-2014-8139.patch
d11758bda3b022f1adb4031bfbc770c6391e3470f3126ec5a4d3d2800d5452245eee26256f539d60adee33f01ba8ba8345299736cd9568da1242f6f739e4a598  CVE-2019-13232.patch
1edd66fbca3cfbfad7b19db0b1564b93f13b27b10ff157cf9907228184b56f1f4c87c2dd2a09afc1307ee86622f3aaeea46f8336c249249c8452304cf4d25272  CVE-2018-18384.patch
"
